var app = getApp(),
  common = require("../../common/common.js");

var false_ques = []


// 模拟交卷时间
var testEndTime = new Date()
var time = testEndTime.getFullYear() + '-' + (testEndTime.getMonth() + 1) + '-' + testEndTime.getDate()

Page({
  data: {
    bgTop: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1545908489055&di=e31df7a4965be3d62f26e43990c0a95d&imgtype=0&src=http%3A%2F%2Fpic8.nipic.com%2F20100808%2F668573_120547067862_2.jpg',
    testEndTime: time,
    okbg:"https://club.wangyc.top/img/correct.png",
    errorbg: "https://club.wangyc.top/img/error.png",

  },
  // 题目 全部解析
  allAnswer(){
    let _t = this.data    

    wx.navigateTo({
      url: '/xc_train/pages/online/error_test/error_test?id=' + _t.all_q
    })
  },
  // 题目 错题解析
  errorAnswer() {
    let _t = this.data
       
    wx.navigateTo({
      url: '/xc_train/pages/online/error_test/error_test?id=' + _t.f_ques
    })
  },
  // 考试结束
  examFinish(_t, category_id, type_id, minute, question_number, right_question){
    app.util.request({
      url: 'entry/wxapp/examFinish',
      data: {
        category_id: category_id,
        type_id: type_id,
        minute: minute,
        question_number: question_number,
        right_question: right_question
      },
      success: function (a) {
        console.log(a)
      }
    })
  },

  // 获取到本次考试的时间题目及格分数
  // startTest(name, id, type, _t) {
  //   type == 1 ? (name = 'category') : (name = 'type')
  //   var startTest = []
  //   var analysis = []
  //   app.util.request({
  //     url: 'entry/wxapp/exam',
  //     data: {
  //       name: name,
  //       cid: id
  //     },
  //     success: function (a) {
  //       console.log(a)
  //       _t.setData({
  //         testQuestion:a.data.data
  //       })
  //     }
  //   })
  // },

  //获取到本次考试的时间题目及格分数
  obtainTestPaper(id) {
    let _t = this;
    app.util.request({
      url: 'entry/wxapp/PaperDetails',
      data: {
        id: id
      },
      success: function (a) {
        console.log(a)
        _t.setData({
          testQuestion: a.data.data
        })
      }
    })
  },


  onLoad: function(w) {
    let _t = this
    let category_id = w.c_id
    let type_id = w.t_id
    let minute = w.min
    let question_number = (w.q_num.split(',')).length
    let all_question_number = w.q_num
    let right_question = (w.r_ques.split(',')).length
    let t_type = w.t_type
    let f_ques = w.f_ques //错题id
    let all_q = w.all_q

    

    _t.examFinish(_t, category_id, type_id, minute, question_number, right_question)

    // 调用 准备题目的接口 获取时间 题数

    //_t.startTest('type', type_id, t_type,_t)

    _t.obtainTestPaper(type_id);
    _t.setData({
      category_id: category_id,
      type_id: type_id,
      minute: minute,
      question_number: question_number,
      right_question: right_question,
      all_question: w.q_num.split(','),
      t_type: t_type,
      f_ques: f_ques,
      all_question_number: all_question_number,
      all_q: all_q
    })

    // 错题存缓存
    let false_ques = f_ques.split(',')    
    // let false_ques = '1,2,3,4'    
    let false_question = ''
    console.log(wx.getStorageSync('false_ques'))
    // 如果当前的 错题缓存为 空 则需要把显示的数据加载到 缓存中  表示是第一次进行 数据缓存处理
    if (wx.getStorageSync('false_ques')==''){
      wx.setStorageSync('false_ques', false_ques)
    }else {
    // 如果不为空 表示之前已经把 错题数据进行了缓存 则需要把最新获得的错题数据添加到 已有的 缓存中
      false_question = wx.getStorageSync('false_ques')
      false_question = false_question + ',' + false_ques
      wx.setStorageSync('false_ques', false_question)
    }

    console.log(false_question)

  }
  
})